package com.superteam.zzl.Des;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.superteam.zzl.activity.R;

import java.util.List;

/**
 * Created by Administrator on 2017/1/11.
 */
public class PutongLAdapter2 extends BaseAdapter{
    private Context context;
    private List<Object>list;

    public PutongLAdapter2(Context context, List<Object> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder vh;
        if (convertView==null){
            vh=new ViewHolder();
            convertView=View.inflate(context,R.layout.putong_list2_item,null);
            vh.imageview=(RzImage) convertView.findViewById(R.id.l2_iv);

            vh.tv1=(TextView)convertView.findViewById(R.id.con);
            vh.tv2=(TextView)convertView.findViewById(R.id.ct);
            vh.tv3=(TextView)convertView.findViewById(R.id.content);
          //  Log.e("sda","sss");
            convertView.setTag(vh);
        }else {
            vh=(ViewHolder)convertView.getTag();
        }
        Object object=list.get(position);
        if (object instanceof Putong2.Data.Index_trends.Trends_list){

            Putong2.Data.Index_trends.Trends_list pditt=(Putong2.Data.Index_trends.Trends_list)object;
            vh.tv1.setText(pditt.author.user_name);
            vh.tv2.setText(pditt.human_ctime);
            vh.tv3.setText(pditt.content);
//            vh.imageview.setTag(pditt.author.avatar);
//            new BitMapAsyncTask(context, new BitMapAsyncTask.CallBack() {
//                @Override
//                public void sendBitMap(String url, Bitmap bitmap) {
//                    if (url.equals(vh.imageview.getTag())){
//                        vh.imageview.setImageBitmap(bitmap);
//                    }
//                }
//            }).execute(pditt.author.avatar);
Glide.with(context).load(pditt.author.avatar).asBitmap().into(new SimpleTarget<Bitmap>() {
    @Override
    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
        vh.imageview.setImageBitmap(resource);
    }



});
//            Glide.with(context).load(pditt.author.avatar).asBitmap().into(new SimpleTarget<GlideDrawable>() {
//                @Override
//                public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
//                    vh.imageview.setImageDrawable(resource);
//                }
//            });

        }else if (object instanceof Putong2.Data.Index_trends.Group_user){
            Putong2.Data.Index_trends.Group_user pdu=(Putong2.Data.Index_trends.Group_user)object;
            vh.tv1.setText(pdu.user_name);
            vh.tv2.setText(pdu.pass_time);
            vh.tv3.setText("laiwana");
//            vh.imageview.setTag(pdu.avatar);
//            new BitMapAsyncTask(context, new BitMapAsyncTask.CallBack() {
//                @Override
//                public void sendBitMap(String url, Bitmap bitmap) {
//                    if (url.equals(vh.imageview.getTag())){
//                        vh.imageview.setImageBitmap(bitmap);
//                    }
//                }
//            }).execute(pdu.avatar);
            Glide.with(context).load(pdu.avatar).asBitmap().into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    vh.imageview.setImageBitmap(resource);
                }



            });
         //   Glide.with(context).load(pdu.avatar).asBitmap().skipMemoryCache(true).into(vh.imageview);
        }

        return convertView;
    }
    class ViewHolder {
        RzImage imageview;
       // ImageView iv;
        TextView tv1,tv2,tv3;
    }
}